<?php
namespace app\admin\controller;

class City extends Admin{
    public function __construct(){
        parent::__construct();
        $this->model = "City";
        $this->assign("model","City");
    }
    public function index(){
        $getData = input('param.');
        $pid = isset($getData['pid']) ? $getData['pid'] : 1;
        $whereData = 'pid='.$pid;
        if ($getData) {
            foreach ($getData as $k=>$v) {
                if ($k == 'pid' || !$v) {
                    continue;
                }
                $whereData .= '&'.$k.'='.$v;
            }
        }
        $this->assign('keywords', isset($getData['keywords']) ? $getData['keywords'] : '');
        $this->assign('pid', $pid);
        $this->assign("whereData",$whereData);
        return $this->fetch();
    }
    protected function get_where_map(){
        $whereData = input("param.whereData/s");
        $whereData = urldecode($whereData);
        $whereDatas = [];
        if ($whereData) {
            $whereData = explode('&', $whereData);
            foreach ($whereData as $v) {
                $r = explode('=', $v);
                if ($r[0] == 'keywords') {
                    $whereDatas['id|title|code'] = ['like', '%'.$r[1].'%'];
                }else{
                    $whereDatas[$r[0]] = $r[1];
                }
            }
        }
        return $whereDatas;
    }
    public function get_city(){
        $code = input('param.code');

        // $where = [];
        // if ($this->uinfo['roleid'] == 1) {
        //     $pid = model('City')->where('code', $code)->value('id');
        //     $where['pid'] = $pid;
        // }else{
        //     $citylist = db('AdminAuth')->where('userid', $this->uinfo['userid'])->where('province_code', $code)->order('id desc')->select();
        //     $citycodes = [];
        //     foreach ($citylist as $v) {
        //         $citycodes[] = $v['city_code'];
        //     }
        //     $where['code'] = ['in', $citycodes];
        // }
        $pid = model('City')->where('code', $code)->value('id');
        $where['pid'] = $pid;
        $list = model('City')->list_data($where);
        return json($list);
    }
}